package io.renren.modules.app.controller;


import io.renren.common.result.Result;
import io.renren.modules.medical.service.OnlineChatService;
import io.renren.modules.medical.vo.weixinVo.ApiChatHistory;
import io.renren.modules.medical.vo.weixinVo.ApiChatListVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 在线私聊接口
 * @author Luo Sheng
 * @school YiBin university
 * @create 2023-04-18 15:05
 */
@RestController
@RequestMapping("/app/chat")
@RequiredArgsConstructor
public class OnlineChatApi {
    private final OnlineChatService onlineChatService;

    /**
     * 根据subId获取聊天用户
     * @return
     */
    @GetMapping("/list/{subId}")
    public Result<List<ApiChatListVo>> list(@PathVariable("subId") Long subId){
        List<ApiChatListVo> chatListVoList = onlineChatService.getChatList(subId);
        return Result.success(chatListVoList);
    }

    /**
     * 通过搜索栏搜索用户
     * @param params
     * @return
     */
    @GetMapping("/search")
    public Result<List<ApiChatListVo>> search(@RequestParam Map<String, Object> params){
        List<ApiChatListVo> chatListVoList = onlineChatService.search(params);
        return Result.success(chatListVoList);
    }

    /**
     * 获得聊天历史
     */
    @GetMapping("/history")
    public Result<List<ApiChatHistory>> history(@RequestParam Map<String, Object> params){
        List<ApiChatHistory> chatListVoList = onlineChatService.history(params);
        return Result.success(chatListVoList);
    }

    /**
     * 清空历史未读
     */
    @GetMapping("/clear/{sendId}/{sendToId}")
    public Result<String> clear(@PathVariable("sendId") Long sendId,
                                @PathVariable("sendToId") Long sendToId){
        onlineChatService.clearNoneVisit(sendId, sendToId);
        return Result.success(null);
    }

}
